package com.zz.tcp.case1;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class Server {
    public static List<Socket> onLineSockets = new ArrayList <>();
    public static void main(String args[]) throws Exception{
        System.out.println("========服务端启动========");
        //1.创建ServerSocket的对象，调用一个accept方法，等待客户端的连接请求
        ServerSocket serverSocket = new ServerSocket(8888);
        while (true){
            //2.使用ServerSocket对象，调用一个accept方法，等待客户端的连接请求
            Socket socket = serverSocket.accept();
            onLineSockets.add(socket);
            System.out.println("有人上线了" + socket.getRemoteSocketAddress());
            //3.把这个客户端对应的socket通信管道，交给一个独立的线程复制处理
            new ServerReaderThread(socket).start();
        }

    }
}
